﻿<!DOCTYPE HTML>
<html>
<head>
<script id="allmobilize" charset="utf-8" src="style/js/allmobilize.min.js"></script>
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="alternate" media="handheld"  />
<!-- end 云适配 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>注册-纽约第一人民医院</title>
<meta property="qc:admins" content="23635710066417756375" />

<meta name="baidu-site-verification" content="QIQ6KC1oZ6" />

<!-- <div class="web_root"  style="display:none">h</div> -->
<script type="text/javascript">
var ctx = "h";
console.log(1);
</script>
<link rel="Shortcut Icon" href="h/images/favicon.ico">
<link rel="stylesheet" type="text/css" href="style/css/style.css"/>

<script src="style/js/jquery.1.10.1.min.js" type="text/javascript"></script>

<script type="text/javascript" src="style/js/jquery.lib.min.js"></script>
<script type="text/javascript" src="style/js/core.min.js"></script>


<script type="text/javascript">
var youdao_conv_id = 271546; 
</script> 
<script type="text/javascript" src="style/js/conv.js"></script>
</head>

<body id="login_bg">
	<div class="login_wrapper">
		<div class="login_header">
        	<a href="index.html"><img src="style/images/leader_default.png" width="285" height="62" alt="注册页" /></a>
            <div id="cloud_s"><img src="style/images/cloud_s.png" width="81" height="52" alt="cloud" /></div>
            <div id="cloud_m"><img src="style/images/cloud_m.png" width="136" height="95"  alt="cloud" /></div>
        </div>
        
    	<input type="hidden" id="resubmitToken" value="9b207beb1e014a93bc852b7ba450db27" />		
		<div class="login_box">
        	<form id="loginForm">

            	<input type="text" id="phone" name="phone" tabindex="1" placeholder="请输入手机号" />
                <span class="error" style="display:none;" id="beError"></span>
                <input type="password" id="password" name="password" tabindex="2" placeholder="请输入密码" />
				<input type="text" id="patientName" name="patientName" tabindex="1" placeholder="请输入您的姓名" />
				<input type="text" id="age" name="age" tabindex="1" placeholder="请输入年龄" />
				<ul class="register_radio clearfix">
					<li>
						男
						<input type="radio" value="男" name="gender" class="register_radio clearfix"/>
					</li>
					<li>
						女
						<input type="radio" value="女" name="gender" class="register_radio clearfix"/>
					</li>
				</ul>
                <input type="submit" id="submitLogin" value="注 &nbsp; &nbsp; 册" />
                

            </form>
            <div class="login_right">
            	<div>已有帐号</div>
            	<a  href="login.html"  class="registor_now">直接登录</a>
            </div>
        </div>
        <div class="login_box_btm"></div>
    </div>
    
    <script type="text/javascript">
    
    $(document).ready(function(e) {
    	$('.register_radio li input').click(function(e){
    		$(this).parent('li').addClass('current').append('<em></em>').siblings().removeClass('current').find('em').remove();
    	});
    	
    	$('#email').focus(function(){
    		$('#beError').hide();
    	});
		//查验手机号是否存在
		jQuery.validator.addMethod("validatePhone", function (value, element) {
			let flag = false;//初始默认值
			$.ajax({
				async: false,//同步请求
				type: "get",
				url: "/patient/existOfPhone",
				data: {
					phone: value
				},
				dataType: "json"  //bug point : no comma
			}).done((result) => {
				flag = !result.data;//true表明号码存在，不能用于注册，false表明不存在，
			}).fail(() => {
				alert("查验手机号码存在失败");
			});
			return flag;
		}, "该手机号码已被注册");
    	//验证表单
	    	 $("#loginForm").validate({
	    	        rules: {
	    	        	gender:{
	    	        		required: true
	    	        	},
			    	   	phone: {
			    	    	required: true,
							validatePhone:true
			    	   	},
						patientName:{
	    	        		required:true,
						},
			    	   	password: {
			    	    	required: true,
			    	    	rangelength: [6,16]
			    	   	},
						age:{
	    	        		required:true,
						}
			    	},
			    	messages: {
			    		gender:{
	    	        		required:"性别为必填项"
	    	        	},
			    	 	phone: {
			    	    	required: "请输入手机号",
			    	    	phone: "请输入您的手机号"
			    	   	},
						patientName:{
			    			required:"请输入姓名"
						},
			    	   	password: {
			    	    	required: "请输入密码",
			    	    	rangelength: "请输入6-16位密码，字母区分大小写"
			    	   	},
						age:{
			    			required:"年龄为必填项"
						}
			    	},
			    	errorPlacement:function(label, element){/* 
			    		if(element.attr("type") == "radio"){
			    			label.insertAfter($(element).parents('ul')).css('marginTop','-20px');
			    		}else if(element.attr("type") == "checkbox"){
			    			label.inserresult.contenttAfter($(element).parent()).css('clear','left');
			    		}else{
			    			label.insertAfter(element);
			    		} */			    		
			    		/*modify nancy*/
			    		if(element.attr("type") == "radio"){
			    			label.insertAfter($(element).parents('ul')).css('marginTop','-20px');
			    		}else if(element.attr("type") == "checkbox"){
			    			label.insertAfter($(element).parent()).css('clear','left');
			    		}else{
			    			label.insertAfter(element);
			    		};	
			    	},
			    	submitHandler:function(form){
			    		let phone = $("#phone").val();
			    		let password = $("#password").val();
			    		let patientName = $("#patientName").val();
			    		let age = $("#age").val();
						let gender = $('input[type="radio"]:checked',form).val();

			    		$(form).find(":submit").attr("disabled", true);

			            $.ajax({
			            	type:'POST',
			            	data: {
			            		phone:phone,
								password:password,
								patientName:patientName,
								age:age,
								gender:gender
							},
			            	url:'/patient/register',
			            	dataType:'json'
			            }).done(function(result) {
		            		if(result.data){
		            			alert("注册成功！");
		            			location.href="login.html";
							}
			            	$(form).find(":submit").attr("disabled", false);			           		
			            }).fail(()=>{
			            	alert("注册失败!请检查必填项");
						});
			        }  
	    	});
    });
    </script>
</body>
</html>
